package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.ticket.domain.PriceTicket;
import cn.wolfcode.luowowo.ticket.domain.Scenic;
import cn.wolfcode.luowowo.ticket.service.IPriceTicketService;
import cn.wolfcode.luowowo.ticket.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("homePage")
public class HomePageController {

    @Reference
    private IPriceTicketService priceTicketService;

    @Reference
    private IScenicService scenicService;


    /**
     *目的地切换
     * 因为点击的是目的地轮换的ajax，所以只查出目的地下面的所有主题门票
     * @param model
     * @param ajaxDestId
     * @return
     */
    @RequestMapping("/reloadSubAndProd")
    public String reloadSubAndProd(Model model, Long ajaxDestId) {//传递进来目的id
        //通过目的地id查询相关的门票
        List<PriceTicket> tickets = priceTicketService.queryDestId(ajaxDestId);
        //把门票传数据传递到页面上
        model.addAttribute("tickets", tickets);
        //通过目的地id查询到对应的主题，并把主题在页面上遍历
        List<Scenic> scenics = scenicService.queryAjaxDestId(ajaxDestId);
        model.addAttribute("scenics", scenics);
        return "ticket/scenicTpl";
    }

    /**
     * 主题切换
     * 通过主题切换查找到相对应的主题下的门票，所以这里需要传递目的地id和主题id
     * @param model
     * @param ajaxDestId
     * @param ajaxSubjectId
     * @return
     */
    @RequestMapping("/reloadProd")
    public String reloadProd(Model model, Long ajaxDestId, Long ajaxSubjectId) {
        //通过目的地id查询到对应的主题，让后通过主题id查询到对应的门票
        List<PriceTicket> priceTickets = priceTicketService.queryDestIdAndScenicId(ajaxDestId, ajaxSubjectId);
        model.addAttribute("priceTickets", priceTickets);

        //通过目的地id查询到对应的主题，并把主题在页面上遍历
//        List<Scenic> scenics = scenicService.queryAjaxDestId(ajaxDestId);
//        model.addAttribute("scenics", scenics);
        return "ticket/TicketTpl";
    }
}
